﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Web;
using System.Web.Helpers;
//using System.Web.Mail;

namespace WebApplication.Core.Helpers
{
    public static class EmailSenderHelper
    {
        //private string address = string.Empty;
        //private string id_hash = string.Empty;
        //private string email = string.Empty;

        //public EmailSenderHelper(string address, string id_hash, string email)
        //{
        //    this.address = address;
        //    this.id_hash = id_hash;
        //    this.email = email;
        //}

        public static void Send(string message, string emailTo, string subject)
        {
            WebMail.SmtpServer = "smtp.gmail.com";
            WebMail.SmtpPort = 587;
            WebMail.EnableSsl = true;
            WebMail.UserName = "alborozd";
            WebMail.Password = "dthibyfjkbvgf";
            WebMail.From = "alborozd@gmail.com";
            WebMail.Send(emailTo, subject, message);

             //MailMessage msg = new MailMessage(
             //    "alborozd@gmail.com",
             //    emailTo,
             //    subject,
             //    message
             //    );

             //SmtpClient smtp = new SmtpClient();
             //smtp.Host = "smtp.gmail.com";
             //smtp.Port = 587;
             //smtp.UseDefaultCredentials = false;
             //smtp.Credentials = new System.Net.NetworkCredential("alborozd", "dthibyfjkbvgf");
             //smtp.EnableSsl = true;
             //smtp.Send(msg);
        }

        public static void Send(string message, string emailTo, string subject, string file)
        {
            //WebMail.SmtpServer = "smtp.gmail.com";
            //WebMail.SmtpPort = 587;
            //WebMail.EnableSsl = true;
            //WebMail.UserName = "alborozd";
            //WebMail.Password = "dthibyfjkbvgf";
            //WebMail.From = "alborozd@gmail.com";
            //WebMail.Send(emailTo, subject, message);

            MailMessage msg = new MailMessage(
                "alborozd@gmail.com",
                emailTo,
                subject,
                message
                );

            Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
            ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(file);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
            disposition.ReadDate = System.IO.File.GetLastAccessTime(file);

            msg.Attachments.Add(data);

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential("alborozd", "dthibyfjkbvgf");
            smtp.EnableSsl = true;
            smtp.Send(msg);
        }
    }
}